/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.ts.domain.query;

import com.xy.biz.ts.domain.enums.TrainNodeEnum;
import com.xy.biz.ts.domain.enums.TrainStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
 *
 *
 * @author wwj
 * @date 2021-4-1
 */
@NoArgsConstructor
@Builder
@AllArgsConstructor
@Data
public class TrainQuery {

    private static final int DEFAULT_PAGE_SIZE = 20;
    public static final int MAX_PAGE_SIZE = 1000;

    /**
     * 返回记录的起始位置。
     */
    private Integer offset;

    /**
     * 返回记录的个数。
     */
    private Integer rows;

    /**
     * 构建一个查询。
     *
     * @param    pageIndex    页索引
     */
    public TrainQuery(Integer pageIndex) {
        this(pageIndex, DEFAULT_PAGE_SIZE);
    }

    /**
     * 构建一个查询。
     *
     * @param    pageIndex    页索引
     * @param    pageSize    页大小
     */
    public TrainQuery(Integer pageIndex, Integer pageSize) {
        int index = pageIndex == null ? 0 : pageIndex;
        int size = pageSize == null ? DEFAULT_PAGE_SIZE : pageSize;
        this.offset = index * size;
        this.rows = size;
    }

    /**
     * 构造符合条件的查询对象，仅返回一条
     *
     * @return
     */
    public static TrainQueryBuilder one() {
        return TrainQuery.builder().offset(0).rows(1);
    }

    /**
     * 构造符合条件的查询对象，控制返回的记录上限
     *
     * @return
     */
    public static TrainQueryBuilder max() {
        return TrainQuery.builder().offset(0).rows(MAX_PAGE_SIZE);
    }

    private Long createUserId;
    /**
     * 阶段：0-未定义
     */
    private String phase;
    /**
     * 流程Id
     */
    private Long documentFlowId;
    /**
     * 培训方式：
     */
    private String mode;
    /**
     * 考核方式
     */
    private String assess;
    /**
     * 培训Id
     */
    private Long trainId;
    /**
     * 培训Id
     */
    private Collection<Long> trainIdS;
    /**
     * 培训分类
     train_year-年度培训
     train_common-普通培训
     */
    private String trainClassify;
    /**
     * 培训人（讲师）用户Id
     */
    private Long trainerUserId;
    /**
     * 开始时间
     */
    private LocalDateTime timeBegin;
    /**
     * 结束时间
     */
    private LocalDateTime timeEnd;
    /**
     * 是否查询发放部门
     */
    private Boolean withUserGroup;
    /**
     * 是否查询自学记录
     */
    private Boolean withLearnRecord;
    /**
     * 是否查询实操记录
     */
    private Boolean withPracticeRecord;
    /**
     * 是否查询考试记录
     */
    private Boolean withExaminationRecord;
    /**
     * 是否只查询发放人员
     */
    private Boolean withUser;
    /**
     * 节点信息
     */
    private Integer nodeType;

    public boolean isWithUserGroup() {
        return Objects.equals(true, this.withUserGroup);
    }

    public boolean isWithLearnRecord() {
        return Objects.equals(true, this.withLearnRecord);
    }

    public boolean isWithPracticeRecord() {
        return Objects.equals(true, this.withPracticeRecord);
    }

    public boolean isWithExaminationRecord() {
        return Objects.equals(true, this.withExaminationRecord);
    }

    public boolean isWithUser() {
        return Objects.equals(true, this.withUser);
    }
}
